
#include "nx_secure_tls_api.h"
#include "tls_test_utility.h"

#if defined(NX_SECURE_ENABLE_ECC_CIPHERSUITE) && !defined(NX_SECURE_X509_DISABLE_CRL) && !defined(NX_SECURE_DISABLE_X509)

/* Test basic X509 parsing with an example certificates. */
#include "test_ca_cert.c"
#include "nx_crypto_ciphersuites_regression.c"

extern void    test_control_return(UINT status);

#define METADATA_SIZE 16000

static UCHAR tls_session_metadata[METADATA_SIZE];
static NX_SECURE_TLS_SESSION tls_session;
extern NX_SECURE_TLS_CRYPTO nx_crypto_tls_ciphers;

/* ecc initialization */
extern const USHORT nx_crypto_ecc_supported_groups[];
extern const NX_CRYPTO_METHOD *nx_crypto_ecc_curves[];
extern const UINT nx_crypto_ecc_supported_groups_size;

static NX_CRYPTO_METHOD test_x509_hash_method = {0};

static NX_CRYPTO_METHOD test_public_cipher_method =
{
    TLS_PUBLIC_AUTH_PSK,                      /* PSK placeholder                        */
    0,                                        /* Key size in bits                       */
    0,                                        /* IV size in bits                        */
    0,                                        /* ICV size in bits, not used.            */
    0,                                        /* Block size in bytes.                   */
    0,                                        /* Metadata size in bytes                 */
    NX_NULL,                                  /* Initialization routine.                */
    NX_NULL,                                  /* Cleanup routine, not used.             */
    NX_NULL                                   /* Operation                              */
};

static NX_CRYPTO_METHOD fake_ecc_curve_method;
static const NX_CRYPTO_METHOD *fake_ecc_curves[2] = {&fake_ecc_curve_method, NX_CRYPTO_NULL};
static USHORT fake_groups[2] = {19, 1};

static const UCHAR TestCA_der[] = {
    0x30, 0x82, 0x03, 0x20, 0x30, 0x82, 0x02, 0x08, 0x02, 0x09, 0x00, 0xc0,
    0xbe, 0x29, 0xae, 0x89, 0x1b, 0xc9, 0xe5, 0x30, 0x0d, 0x06, 0x09, 0x2a,
    0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x52,
    0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43,
    0x4e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x02,
    0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c,
    0x02, 0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a,
    0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
    0x0b, 0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55,
    0x04, 0x03, 0x0c, 0x06, 0x54, 0x65, 0x73, 0x74, 0x43, 0x41, 0x30, 0x1e,
    0x17, 0x0d, 0x31, 0x37, 0x31, 0x31, 0x30, 0x39, 0x30, 0x32, 0x33, 0x33,
    0x31, 0x39, 0x5a, 0x17, 0x0d, 0x32, 0x30, 0x30, 0x38, 0x32, 0x39, 0x30,
    0x32, 0x33, 0x33, 0x31, 0x39, 0x5a, 0x30, 0x52, 0x31, 0x0b, 0x30, 0x09,
    0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43, 0x4e, 0x31, 0x0b, 0x30,
    0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x02, 0x53, 0x48, 0x31, 0x0b,
    0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x02, 0x53, 0x48, 0x31,
    0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x45, 0x4c,
    0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x02, 0x45,
    0x4c, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x06,
    0x54, 0x65, 0x73, 0x74, 0x43, 0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d,
    0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05,
    0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82,
    0x01, 0x01, 0x00, 0xc3, 0x79, 0x72, 0xa4, 0xe2, 0xc6, 0xb7, 0x5d, 0x0f,
    0x41, 0x8c, 0x8e, 0xd1, 0x3c, 0xfd, 0x97, 0xf4, 0x8e, 0x82, 0x7e, 0x75,
    0xac, 0x4d, 0x85, 0xbb, 0xba, 0xe3, 0xd6, 0x22, 0xad, 0xc5, 0xc2, 0xd5,
    0x9d, 0x78, 0x1c, 0xab, 0x9c, 0x33, 0xb7, 0x95, 0x36, 0xcb, 0x63, 0x76,
    0x88, 0xc7, 0x3c, 0xa7, 0xf7, 0xfb, 0x84, 0x1d, 0x7c, 0xc5, 0x17, 0x25,
    0x5f, 0x1d, 0x41, 0xf3, 0x8c, 0xf9, 0x2f, 0x93, 0xab, 0xb2, 0x6b, 0x84,
    0xa9, 0x07, 0x70, 0xa1, 0xa0, 0xb3, 0xe0, 0x86, 0x5b, 0x5f, 0x4e, 0x0c,
    0x78, 0x7f, 0x20, 0x10, 0x12, 0x60, 0x13, 0x5c, 0xf8, 0x15, 0xe0, 0xc6,
    0xcb, 0xb2, 0x61, 0xe4, 0x78, 0x9d, 0xb8, 0x91, 0x60, 0x0f, 0xe6, 0xce,
    0xa4, 0x57, 0xa9, 0xb3, 0xb1, 0x9e, 0x3b, 0xc7, 0xf1, 0x66, 0x96, 0x23,
    0xf7, 0xe5, 0x40, 0xfa, 0xf6, 0x3a, 0xb9, 0x32, 0x64, 0xd0, 0x01, 0x14,
    0x31, 0x81, 0x3c, 0x3e, 0xf1, 0x9e, 0x64, 0x3d, 0xd0, 0x37, 0xee, 0xcd,
    0xf1, 0x82, 0x79, 0x3e, 0x08, 0x48, 0x2d, 0x2f, 0xa4, 0x5d, 0x41, 0xff,
    0x1f, 0xc1, 0x99, 0x26, 0x53, 0xb8, 0x7b, 0x59, 0xe5, 0x79, 0x9d, 0x25,
    0x2c, 0x35, 0xe6, 0x7b, 0x22, 0x02, 0x8c, 0x78, 0x05, 0xda, 0x90, 0x5d,
    0xbd, 0xd4, 0x53, 0xca, 0xa2, 0x73, 0xcc, 0xa0, 0xd7, 0x63, 0x3c, 0x22,
    0xe4, 0x2a, 0xb8, 0xc8, 0x5f, 0x58, 0x74, 0xce, 0x6c, 0x3b, 0xf3, 0x21,
    0x9a, 0xfa, 0xa0, 0x40, 0xc3, 0x10, 0x32, 0x46, 0xbb, 0x14, 0xff, 0xd6,
    0x1c, 0x41, 0x90, 0xb1, 0xb0, 0x0b, 0x59, 0x18, 0xaa, 0xfd, 0x43, 0x63,
    0x4b, 0x7c, 0xf1, 0x68, 0x1d, 0xa7, 0xed, 0x2c, 0x35, 0x11, 0xb8, 0xbc,
    0x02, 0x27, 0xc6, 0x39, 0x48, 0x62, 0x2b, 0xc1, 0xa9, 0x08, 0x53, 0x1f,
    0x7c, 0xdb, 0xa1, 0x6d, 0x41, 0x58, 0xc5, 0x02, 0x03, 0x01, 0x00, 0x01,
    0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
    0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x3d, 0xa4, 0x36, 0xc9,
    0x9d, 0x91, 0xd1, 0x25, 0xe7, 0x41, 0x2c, 0x8d, 0xda, 0xcd, 0xb3, 0x8a,
    0x53, 0xe4, 0xee, 0x4f, 0x94, 0xa4, 0x84, 0xee, 0xaf, 0x06, 0x85, 0x6a,
    0xa6, 0x54, 0xe5, 0x8f, 0x12, 0xd3, 0x5e, 0x84, 0x33, 0x7a, 0x1d, 0x66,
    0x24, 0xb0, 0x9d, 0x94, 0x71, 0xad, 0x5b, 0x91, 0x6d, 0x06, 0xf3, 0x7b,
    0x41, 0x8f, 0x1a, 0x97, 0xa2, 0xe9, 0x52, 0x57, 0x2e, 0xfb, 0xaf, 0x1f,
    0xb7, 0xf9, 0x9c, 0xf8, 0xa9, 0xde, 0x4e, 0xdb, 0x92, 0x92, 0x94, 0xe0,
    0x06, 0x50, 0xfa, 0x76, 0x4f, 0x45, 0xeb, 0x8f, 0x60, 0x49, 0xeb, 0x98,
    0x32, 0x65, 0xb9, 0x85, 0xc4, 0x21, 0x81, 0xe3, 0x81, 0x33, 0x41, 0x45,
    0xc4, 0xbc, 0x3b, 0xda, 0x7a, 0x74, 0xe8, 0x4e, 0x3e, 0xc9, 0x39, 0xdf,
    0xdd, 0xa0, 0xb3, 0x49, 0x76, 0x58, 0x13, 0x46, 0x74, 0x66, 0x9e, 0xc1,
    0xbc, 0x6b, 0x37, 0xb8, 0x77, 0x6a, 0x8e, 0xf1, 0x6a, 0xad, 0xb4, 0x75,
    0x13, 0x1b, 0x2b, 0x3f, 0x62, 0x5e, 0xc7, 0x18, 0x6f, 0x65, 0xfa, 0x5c,
    0xc6, 0xb3, 0xf9, 0xa2, 0x83, 0xfa, 0x79, 0x50, 0xfa, 0xa8, 0xc8, 0xa7,
    0xc5, 0xeb, 0x7d, 0x4a, 0x27, 0x82, 0xe5, 0x09, 0xfb, 0x20, 0x06, 0x25,
    0x0a, 0x35, 0x4e, 0x43, 0x01, 0x2e, 0x09, 0x41, 0x8d, 0x1d, 0xf5, 0x4e,
    0x58, 0x72, 0x3c, 0x52, 0x34, 0x25, 0x64, 0xb6, 0xc5, 0x24, 0x9c, 0xd8,
    0xe4, 0xc9, 0xe6, 0xee, 0x23, 0xce, 0xa8, 0x1d, 0x46, 0xd0, 0xc8, 0xd6,
    0x8f, 0x27, 0xc1, 0x48, 0x66, 0x3d, 0x30, 0x7f, 0xf4, 0xf5, 0xd7, 0x81,
    0x3a, 0x62, 0x92, 0xbb, 0x9a, 0x66, 0x65, 0xaf, 0x27, 0x93, 0xd8, 0x63,
    0xfa, 0xa8, 0x3f, 0x14, 0x2e, 0xbd, 0xd2, 0x20, 0x30, 0x5b, 0x41, 0x6d,
    0x01, 0x07, 0x37, 0xe9, 0x9c, 0x8a, 0x07, 0xe3, 0x32, 0xb7, 0x68, 0xae
};

static const UCHAR TestCA_crl[] = {
    0x30, 0x82, 0x01, 0xb6, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a,
    0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x04, 0x05, 0x00, 0x30, 0x52,
    0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43,
    0x4e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x02,
    0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c,
    0x02, 0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a,
    0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
    0x0b, 0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55,
    0x04, 0x03, 0x0c, 0x06, 0x54, 0x65, 0x73, 0x74, 0x43, 0x41, 0x17, 0x0d,
    0x31, 0x37, 0x31, 0x31, 0x31, 0x30, 0x30, 0x37, 0x32, 0x35, 0x33, 0x34,
    0x5a, 0x17, 0x0d, 0x31, 0x37, 0x31, 0x32, 0x31, 0x30, 0x30, 0x37, 0x32,
    0x35, 0x33, 0x34, 0x5a, 0x30, 0x1c, 0x30, 0x1a, 0x02, 0x09, 0x00, 0xe8,
    0xc2, 0xa4, 0x9c, 0x7c, 0x44, 0xb8, 0x59, 0x17, 0x0d, 0x31, 0x37, 0x31,
    0x31, 0x31, 0x30, 0x30, 0x37, 0x31, 0x33, 0x34, 0x34, 0x5a, 0x30, 0x0d,
    0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x04, 0x05,
    0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x90, 0x24, 0x79, 0x99, 0x0f, 0x11,
    0x72, 0x75, 0xf6, 0xeb, 0xb8, 0xef, 0x0e, 0xa7, 0xb5, 0x8e, 0x1b, 0xc5,
    0xdb, 0xe7, 0x5a, 0xfd, 0x58, 0x85, 0x06, 0x65, 0xf7, 0x2e, 0x62, 0x4d,
    0xbe, 0x39, 0x14, 0x1c, 0x31, 0x18, 0xb5, 0x04, 0x65, 0x6b, 0x32, 0x33,
    0x6f, 0x70, 0xe9, 0x8b, 0x1b, 0x6c, 0x43, 0xe1, 0xf7, 0xba, 0xb6, 0x10,
    0x54, 0xef, 0x23, 0x61, 0xf6, 0x84, 0x8a, 0xa5, 0x3a, 0x9a, 0x4c, 0x27,
    0x13, 0xdb, 0x04, 0x85, 0x52, 0x08, 0x4d, 0xbd, 0xae, 0x23, 0x03, 0x8b,
    0x68, 0xe8, 0x7f, 0xfe, 0xd4, 0xcb, 0xeb, 0x49, 0x81, 0x37, 0x98, 0x72,
    0x0d, 0xe3, 0x60, 0xac, 0x5d, 0xbd, 0xa8, 0x78, 0x3a, 0xcf, 0xc7, 0x8c,
    0x82, 0x4f, 0x19, 0xfd, 0xb9, 0x01, 0x17, 0x66, 0x7e, 0xd2, 0x8b, 0x3d,
    0x1f, 0x3e, 0xcc, 0x37, 0x6c, 0x23, 0x35, 0xf2, 0x3c, 0x53, 0x82, 0x7f,
    0xba, 0x46, 0xfa, 0x4f, 0x66, 0x92, 0xdb, 0x95, 0xd1, 0xef, 0xdb, 0x19,
    0x98, 0x4b, 0x8e, 0xdf, 0xea, 0xb3, 0xaa, 0x9a, 0x45, 0x1a, 0xda, 0xd7,
    0x57, 0x36, 0x0e, 0xaa, 0x37, 0xf2, 0x57, 0x0d, 0xc9, 0x94, 0xf4, 0x50,
    0x43, 0x33, 0x5a, 0x99, 0x96, 0x0f, 0xdf, 0x23, 0x71, 0xe1, 0xd4, 0xf5,
    0x9b, 0x34, 0x89, 0xd2, 0xb3, 0xbf, 0xe6, 0xd5, 0x99, 0x95, 0xa4, 0x85,
    0x6b, 0xb1, 0xc7, 0x4d, 0x64, 0x0b, 0xf3, 0xf6, 0x9f, 0xda, 0xc2, 0x09,
    0x61, 0xa8, 0x22, 0x4c, 0xa8, 0xdb, 0xcb, 0x9c, 0x4a, 0xf5, 0xbd, 0xcb,
    0x9b, 0xa1, 0x8d, 0xa6, 0xe6, 0xde, 0xf3, 0xf9, 0xc9, 0xc7, 0x49, 0x3f,
    0xc0, 0xbb, 0x67, 0xec, 0xc9, 0x1b, 0x10, 0xc7, 0x7a, 0x84, 0x24, 0xab,
    0xc6, 0x5d, 0x21, 0x3a, 0xc7, 0xdd, 0xd1, 0xb7, 0x1f, 0xe3, 0x71, 0x47,
    0xb8, 0xac, 0x77, 0xc9, 0xf9, 0xf2, 0xf8, 0x5e, 0x1e, 0x6d
};

static const UCHAR domain_com_der[] = {
    0x30, 0x82, 0x03, 0xfe, 0x30, 0x82, 0x02, 0xe6, 0xa0, 0x03, 0x02, 0x01,
    0x02, 0x02, 0x09, 0x00, 0xe8, 0xc2, 0xa4, 0x9c, 0x7c, 0x44, 0xb8, 0x59,
    0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
    0x0b, 0x05, 0x00, 0x30, 0x52, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
    0x04, 0x06, 0x13, 0x02, 0x43, 0x4e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
    0x55, 0x04, 0x08, 0x0c, 0x02, 0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06,
    0x03, 0x55, 0x04, 0x07, 0x0c, 0x02, 0x53, 0x48, 0x31, 0x0b, 0x30, 0x09,
    0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0b, 0x30,
    0x09, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0f,
    0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x06, 0x54, 0x65, 0x73,
    0x74, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x37, 0x31, 0x31, 0x30,
    0x39, 0x30, 0x39, 0x30, 0x35, 0x34, 0x32, 0x5a, 0x17, 0x0d, 0x32, 0x30,
    0x30, 0x38, 0x32, 0x39, 0x30, 0x39, 0x30, 0x35, 0x34, 0x32, 0x5a, 0x30,
    0x56, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
    0x43, 0x4e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
    0x02, 0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x07,
    0x0c, 0x02, 0x53, 0x48, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
    0x0a, 0x0c, 0x02, 0x45, 0x4c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
    0x04, 0x0b, 0x0c, 0x02, 0x45, 0x4c, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03,
    0x55, 0x04, 0x03, 0x0c, 0x0a, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x2e,
    0x63, 0x6f, 0x6d, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a,
    0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82,
    0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00,
    0xca, 0xda, 0xad, 0xb7, 0xf0, 0x38, 0xb4, 0xab, 0x57, 0x90, 0x7f, 0x17,
    0xc9, 0x27, 0x19, 0x3f, 0x38, 0x8b, 0xc4, 0x33, 0x48, 0x4e, 0x79, 0xe6,
    0x86, 0x0e, 0x9d, 0x80, 0xa1, 0xd1, 0x59, 0xf5, 0xcb, 0x00, 0x4b, 0x7a,
    0xb4, 0x2d, 0xdf, 0x1d, 0xc5, 0x88, 0x4f, 0x82, 0xf7, 0x5f, 0x88, 0x96,
    0xc0, 0xb7, 0xc6, 0x8e, 0x7b, 0x58, 0x89, 0xa8, 0xe5, 0x2d, 0xf6, 0x00,
    0xf5, 0xb7, 0x2d, 0x7e, 0x65, 0x0a, 0x93, 0x8b, 0x75, 0x4f, 0x2d, 0xec,
    0xb3, 0xc3, 0x42, 0xc5, 0x12, 0x0d, 0xb4, 0x5b, 0xe2, 0xd6, 0x37, 0x11,
    0x24, 0x1b, 0x80, 0x80, 0xe7, 0xf7, 0x5c, 0xb0, 0x32, 0x7c, 0xd0, 0x39,
    0x6a, 0x28, 0x79, 0x17, 0x60, 0xf0, 0x50, 0x7f, 0x8d, 0xaf, 0x8d, 0x13,
    0x11, 0xf4, 0x61, 0x1b, 0xb6, 0x49, 0x53, 0x17, 0x06, 0x76, 0x8a, 0xb3,
    0xe5, 0x38, 0xf0, 0xe8, 0x33, 0x25, 0x18, 0x7c, 0xf3, 0x03, 0x6c, 0x4b,
    0x48, 0x63, 0x2e, 0xe7, 0xa5, 0xe1, 0x39, 0x10, 0xcd, 0xc9, 0xdf, 0x4a,
    0x9e, 0x29, 0xcb, 0x4e, 0x75, 0x02, 0x0f, 0x28, 0xb1, 0x57, 0xf6, 0xd5,
    0x6f, 0x64, 0x23, 0xd5, 0xcb, 0xfd, 0x9d, 0x11, 0x96, 0xb4, 0x34, 0x99,
    0xe2, 0xaf, 0x8f, 0xe2, 0xd6, 0x31, 0xf2, 0x8a, 0x3a, 0x32, 0x6a, 0x91,
    0x8c, 0x3f, 0xdf, 0x49, 0xd9, 0xd0, 0x89, 0x76, 0x96, 0x1b, 0xfe, 0xee,
    0x50, 0x0d, 0xc3, 0x40, 0xad, 0x00, 0x24, 0xbc, 0x62, 0x3d, 0xb2, 0xe4,
    0x68, 0xe0, 0xbf, 0xf3, 0x02, 0xe5, 0xd4, 0x1b, 0xa8, 0xa9, 0x1c, 0xc8,
    0xbd, 0xe7, 0x4c, 0xd2, 0x3b, 0x46, 0xfe, 0x3d, 0x0c, 0x80, 0x82, 0x0f,
    0xc3, 0xea, 0x60, 0x7e, 0x23, 0x97, 0xd9, 0x97, 0x0c, 0xb0, 0x87, 0x05,
    0x3f, 0x36, 0x8b, 0x76, 0x28, 0x3d, 0x2e, 0xa8, 0x20, 0xdd, 0x5c, 0x7d,
    0xb3, 0x25, 0xc2, 0xb7, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x81, 0xd2,
    0x30, 0x81, 0xcf, 0x30, 0x6c, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x65,
    0x30, 0x63, 0xa1, 0x56, 0xa4, 0x54, 0x30, 0x52, 0x31, 0x0b, 0x30, 0x09,
    0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43, 0x4e, 0x31, 0x0b, 0x30,
    0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x02, 0x53, 0x48, 0x31, 0x0b,
    0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x02, 0x53, 0x48, 0x31,
    0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x45, 0x4c,
    0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x02, 0x45,
    0x4c, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x06,
    0x54, 0x65, 0x73, 0x74, 0x43, 0x41, 0x82, 0x09, 0x00, 0xc0, 0xbe, 0x29,
    0xae, 0x89, 0x1b, 0xc9, 0xe5, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13,
    0x04, 0x02, 0x30, 0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04,
    0x04, 0x03, 0x02, 0x04, 0xf0, 0x30, 0x47, 0x06, 0x03, 0x55, 0x1d, 0x11,
    0x04, 0x40, 0x30, 0x3e, 0x82, 0x0e, 0x77, 0x77, 0x77, 0x2e, 0x64, 0x6f,
    0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x0c, 0x2a, 0x2e,
    0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x0e,
    0x61, 0x2a, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63,
    0x6f, 0x6d, 0x82, 0x0e, 0x2a, 0x62, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70,
    0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
    0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01,
    0x01, 0x00, 0x7e, 0xfe, 0x0c, 0x03, 0x19, 0x7d, 0xfe, 0x4b, 0x6c, 0xa8,
    0xe6, 0x84, 0x68, 0xa5, 0x7f, 0x53, 0x82, 0x64, 0xf0, 0x8d, 0x23, 0xf3,
    0x0e, 0x53, 0x15, 0x79, 0x8f, 0xb9, 0x95, 0xa3, 0x31, 0xe4, 0x85, 0x73,
    0xfa, 0xf9, 0x74, 0x75, 0xd8, 0x76, 0x39, 0xa8, 0x82, 0x49, 0x8a, 0x8e,
    0xeb, 0x20, 0xfe, 0x2a, 0x46, 0xe8, 0xe1, 0x5b, 0xc3, 0x27, 0x17, 0xea,
    0x9d, 0x09, 0xe7, 0x7b, 0xde, 0x8e, 0x98, 0x18, 0x19, 0x6a, 0xaf, 0xe8,
    0x6e, 0xac, 0x56, 0x5a, 0xdd, 0x6b, 0x36, 0xc7, 0xc5, 0xc1, 0xca, 0x75,
    0x92, 0xc0, 0x47, 0x07, 0x1d, 0xea, 0x4c, 0x50, 0x24, 0x46, 0x35, 0x5e,
    0xc6, 0x6b, 0x46, 0x01, 0x0d, 0x7b, 0xf2, 0xb9, 0x89, 0x4c, 0x10, 0xef,
    0xee, 0xe8, 0xd6, 0xb1, 0x70, 0x10, 0x82, 0x57, 0xf2, 0xc8, 0xc0, 0xe9,
    0xbd, 0xac, 0xec, 0x8e, 0x0f, 0x9a, 0xd6, 0xaf, 0x9c, 0x45, 0x30, 0x0b,
    0x43, 0x6a, 0x0c, 0x14, 0x7f, 0x70, 0x62, 0xaa, 0x19, 0x3a, 0x9d, 0x25,
    0x87, 0xec, 0x39, 0xc4, 0x0f, 0xca, 0xbf, 0x7d, 0xe6, 0x23, 0x24, 0x41,
    0x04, 0xc8, 0xb2, 0x0e, 0x45, 0x6d, 0xe6, 0xf4, 0x00, 0x86, 0x12, 0xde,
    0x49, 0x01, 0x2b, 0xcf, 0x75, 0x3e, 0x9b, 0x51, 0x63, 0xe4, 0xe7, 0x1e,
    0x55, 0x6a, 0x84, 0x07, 0x50, 0xcb, 0xc9, 0x26, 0x90, 0xf1, 0x11, 0xab,
    0x10, 0xad, 0x13, 0xef, 0x83, 0x72, 0x85, 0x78, 0xfa, 0x93, 0x55, 0x39,
    0x7e, 0x17, 0xe1, 0x01, 0x71, 0xbc, 0xcf, 0x77, 0x1c, 0x7f, 0x13, 0x71,
    0x99, 0x20, 0x52, 0xf6, 0x57, 0x2b, 0x38, 0x30, 0x4a, 0x37, 0xf9, 0x74,
    0x7f, 0x94, 0xff, 0x2b, 0x55, 0x6d, 0x66, 0x91, 0x91, 0x23, 0xbb, 0x8d,
    0xa7, 0x0d, 0x5c, 0x87, 0x26, 0x44, 0x8b, 0x23, 0x1a, 0xd7, 0x3c, 0x0a,
    0x71, 0xb5, 0x0e, 0xe6, 0x1b, 0x66
};

static UINT test_crypto_init(struct NX_CRYPTO_METHOD_STRUCT *method,
                           UCHAR *key, NX_CRYPTO_KEY_SIZE key_size_in_bits,
                           VOID **handler,
                           VOID *crypto_metadata,
                           ULONG crypto_metadata_size)
{
    return NX_CRYPTO_NOT_SUCCESSFUL;
}

static UINT test_crypto_cleanup(VOID *crypto_metadata)
{
    return NX_CRYPTO_NOT_SUCCESSFUL;
}

static UINT test_crypto_operation(UINT op,       /* Encrypt, Decrypt, Authenticate */
                                VOID *handler, /* Crypto handler */
                                struct NX_CRYPTO_METHOD_STRUCT *method,
                                UCHAR *key,
                                NX_CRYPTO_KEY_SIZE key_size_in_bits,
                                UCHAR *input,
                                ULONG input_length_in_byte,
                                UCHAR *iv_ptr,
                                UCHAR *output,
                                ULONG output_length_in_byte,
                                VOID *crypto_metadata,
                                ULONG crypto_metadata_size,
                                VOID *packet_ptr,
                                VOID (*nx_crypto_hw_process_callback)(VOID *packet_ptr, UINT status))
{
    return NX_CRYPTO_NOT_SUCCESSFUL;
}

static UINT test_crypto_operation_2(UINT op,       /* Encrypt, Decrypt, Authenticate */
                                VOID *handler, /* Crypto handler */
                                struct NX_CRYPTO_METHOD_STRUCT *method,
                                UCHAR *key,
                                NX_CRYPTO_KEY_SIZE key_size_in_bits,
                                UCHAR *input,
                                ULONG input_length_in_byte,
                                UCHAR *iv_ptr,
                                UCHAR *output,
                                ULONG output_length_in_byte,
                                VOID *crypto_metadata,
                                ULONG crypto_metadata_size,
                                VOID *packet_ptr,
                                VOID (*nx_crypto_hw_process_callback)(VOID *packet_ptr, UINT status))
{
    if(op == NX_CRYPTO_EC_CURVE_SET)
    {
        return NX_CRYPTO_SUCCESS;
    }

    return NX_CRYPTO_NOT_SUCCESSFUL;
}

static UINT test_nx_crypto_method_md5_operation(UINT op,       /* Encrypt, Decrypt, Authenticate */
                                VOID *handler, /* Crypto handler */
                                struct NX_CRYPTO_METHOD_STRUCT *method,
                                UCHAR *key,
                                NX_CRYPTO_KEY_SIZE key_size_in_bits,
                                UCHAR *input,
                                ULONG input_length_in_byte,
                                UCHAR *iv_ptr,
                                UCHAR *output,
                                ULONG output_length_in_byte,
                                VOID *crypto_metadata,
                                ULONG crypto_metadata_size,
                                VOID *packet_ptr,
                                VOID (*nx_crypto_hw_process_callback)(VOID *packet_ptr, UINT status))
{
    UINT status;

    status = crypto_method_md5.nx_crypto_operation(op, handler, method, key, key_size_in_bits, input,
        input_length_in_byte, iv_ptr, output, output_length_in_byte, crypto_metadata,
        crypto_metadata_size, packet_ptr, nx_crypto_hw_process_callback);

    if((op == NX_CRYPTO_VERIFY) && output)
    {
        memset(output, 0, output_length_in_byte);
    }

    return status;
}

static NX_CRYPTO_METHOD test_crypto_method_md5;

static NX_SECURE_X509_CRYPTO test_x509_cipher_table[] =
{
    /* OID identifier,                        public cipher,            hash method */
    {NX_SECURE_TLS_X509_TYPE_RSA_MD5,    &test_public_cipher_method,    &test_x509_hash_method},
};

static NX_SECURE_X509_CRYPTO test_x509_cipher_table_2[] =
{
    {NX_SECURE_TLS_X509_TYPE_RSA_MD5,    &crypto_method_rsa,       &test_crypto_method_md5},
};

#ifdef CTEST
void test_application_define(void *first_unused_memory);
void test_application_define(void *first_unused_memory)
#else
void nx_secure_x509_crl_verify_test_application_define(void *first_unused_memory)
#endif
{
UINT status;
NX_SECURE_X509_CERT trusted_certificate;
NX_SECURE_X509_CERT revoked_certificate;
NX_SECURE_X509_CERTIFICATE_STORE *store;
NX_SECURE_X509_CRL crl;
UINT crl_bytes;

    /* Print out test information banner.  */
    printf("NetX Secure Test:   TLS X509 CRL Verify Test.......................");

    nx_system_initialize();

    status =  nx_secure_tls_session_create(&tls_session,
                                           &nx_crypto_tls_ciphers,
                                           tls_session_metadata,
                                           sizeof(tls_session_metadata));
    EXPECT_EQ(NX_SUCCESS, status);

    store = &tls_session.nx_secure_tls_credentials.nx_secure_tls_certificate_store;

    status = nx_secure_x509_certificate_initialize(&trusted_certificate, (UCHAR*)TestCA_der, sizeof(TestCA_der), NX_NULL, 0, NX_NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE);
    EXPECT_EQ(NX_SUCCESS, status);

    status = nx_secure_tls_trusted_certificate_add(&tls_session, &trusted_certificate);
    EXPECT_EQ(NX_SUCCESS, status);

    status = nx_secure_x509_certificate_initialize(&revoked_certificate, (UCHAR*)domain_com_der, sizeof(domain_com_der), NX_NULL, 0, NX_NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE);
    EXPECT_EQ(NX_SUCCESS, status);

    status = nx_secure_tls_local_certificate_add(&tls_session, &revoked_certificate);
    EXPECT_EQ(NX_SUCCESS, status);

    memcpy(&test_crypto_method_md5, &crypto_method_md5, sizeof(NX_CRYPTO_METHOD));
    test_crypto_method_md5.nx_crypto_operation = test_nx_crypto_method_md5_operation;
    revoked_certificate.nx_secure_x509_cipher_table = test_x509_cipher_table_2;
    revoked_certificate.nx_secure_x509_cipher_table_size = 1;

    status = nx_secure_x509_crl_revocation_check(TestCA_crl, sizeof(TestCA_crl), store, &revoked_certificate);
    EXPECT_EQ(NX_SECURE_X509_CRL_SIGNATURE_CHECK_FAILED, status);

    revoked_certificate.nx_secure_x509_cipher_table = test_x509_cipher_table;
    revoked_certificate.nx_secure_x509_cipher_table_size = 1;

    test_x509_hash_method.nx_crypto_init = test_crypto_init;
    status = nx_secure_x509_crl_revocation_check(TestCA_crl, sizeof(TestCA_crl), store, &revoked_certificate);
    EXPECT_EQ(NX_CRYPTO_NOT_SUCCESSFUL, status);
    test_x509_hash_method.nx_crypto_init = NX_NULL;

    test_x509_hash_method.nx_crypto_operation = test_crypto_operation;
    status = nx_secure_x509_crl_revocation_check(TestCA_crl, sizeof(TestCA_crl), store, &revoked_certificate);
    EXPECT_EQ(NX_CRYPTO_NOT_SUCCESSFUL, status);
    test_x509_hash_method.nx_crypto_operation = NX_NULL;

    test_x509_hash_method.nx_crypto_cleanup = test_crypto_cleanup;
    status = nx_secure_x509_crl_revocation_check(TestCA_crl, sizeof(TestCA_crl), store, &revoked_certificate);
    EXPECT_EQ(NX_CRYPTO_NOT_SUCCESSFUL, status);
    test_x509_hash_method.nx_crypto_cleanup = NX_NULL;

    test_public_cipher_method.nx_crypto_algorithm = NX_CRYPTO_DIGITAL_SIGNATURE_RSA;
    
    test_public_cipher_method.nx_crypto_init = test_crypto_init;
    status = nx_secure_x509_crl_revocation_check(TestCA_crl, sizeof(TestCA_crl), store, &revoked_certificate);
    EXPECT_EQ(NX_CRYPTO_NOT_SUCCESSFUL, status);
    test_public_cipher_method.nx_crypto_init = NX_NULL;

    test_public_cipher_method.nx_crypto_operation = test_crypto_operation;
    status = nx_secure_x509_crl_revocation_check(TestCA_crl, sizeof(TestCA_crl), store, &revoked_certificate);
    EXPECT_EQ(NX_CRYPTO_NOT_SUCCESSFUL, status);
    test_public_cipher_method.nx_crypto_operation = NX_NULL;

    test_public_cipher_method.nx_crypto_cleanup = test_crypto_cleanup;
    status = nx_secure_x509_crl_revocation_check(TestCA_crl, sizeof(TestCA_crl), store, &revoked_certificate);
    EXPECT_EQ(NX_CRYPTO_NOT_SUCCESSFUL, status);
    test_public_cipher_method.nx_crypto_cleanup = NX_NULL;

    status = nx_secure_x509_crl_revocation_check(TestCA_crl, sizeof(TestCA_crl), store, &revoked_certificate);
#ifdef NX_SECURE_KEY_CLEAR
    EXPECT_EQ(NX_SECURE_X509_PKCS7_PARSING_FAILED, status); /* Unable to decode PKCS7 when signature is all zero. */
#else
    EXPECT_EQ(NX_SECURE_X509_WRONG_SIGNATURE_METHOD, status);
#endif

    status = _nx_secure_x509_certificate_revocation_list_parse(TestCA_crl, sizeof(TestCA_crl), &crl_bytes, &crl);
    EXPECT_EQ(NX_SUCCESS, status);

    trusted_certificate.nx_secure_x509_public_algorithm = 0;
    status = _nx_secure_x509_crl_verify(&revoked_certificate, &crl, store, &trusted_certificate);
    EXPECT_EQ(NX_SECURE_X509_WRONG_SIGNATURE_METHOD, status);

    test_public_cipher_method.nx_crypto_algorithm = NX_CRYPTO_DIGITAL_SIGNATURE_ECDSA;
        
    status = _nx_secure_x509_crl_verify(&revoked_certificate, &crl, store, &trusted_certificate);
    EXPECT_EQ(NX_SECURE_X509_WRONG_SIGNATURE_METHOD, status);

    trusted_certificate.nx_secure_x509_public_algorithm = NX_SECURE_TLS_X509_TYPE_EC;
    status = _nx_secure_x509_crl_verify(&revoked_certificate, &crl, store, &trusted_certificate);
    EXPECT_EQ(NX_CRYTPO_MISSING_ECC_CURVE, status);

    /* set up the curves */
    status = nx_secure_tls_ecc_initialize(&tls_session, fake_groups, 2, &fake_ecc_curves[0]);
    EXPECT_EQ(NX_SUCCESS, status);

    trusted_certificate.nx_secure_x509_public_key.ec_public_key.nx_secure_ec_named_curve = fake_groups[1];
    status = _nx_secure_x509_crl_verify(&revoked_certificate, &crl, store, &trusted_certificate);
    EXPECT_EQ(NX_SECURE_X509_UNSUPPORTED_PUBLIC_CIPHER, status);

    trusted_certificate.nx_secure_x509_public_key.ec_public_key.nx_secure_ec_named_curve = fake_groups[0];
    test_public_cipher_method.nx_crypto_init = test_crypto_init;
    status = _nx_secure_x509_crl_verify(&revoked_certificate, &crl, store, &trusted_certificate);
    EXPECT_EQ(NX_CRYPTO_NOT_SUCCESSFUL, status);
    test_public_cipher_method.nx_crypto_init = NX_NULL;

    status = _nx_secure_x509_crl_verify(&revoked_certificate, &crl, store, &trusted_certificate);
    EXPECT_EQ(NX_SECURE_X509_MISSING_CRYPTO_ROUTINE, status);

    test_public_cipher_method.nx_crypto_operation = test_crypto_operation;
    status = _nx_secure_x509_crl_verify(&revoked_certificate, &crl, store, &trusted_certificate);
    EXPECT_EQ(NX_CRYPTO_NOT_SUCCESSFUL, status);

    test_public_cipher_method.nx_crypto_operation = test_crypto_operation_2;
    status = _nx_secure_x509_crl_verify(&revoked_certificate, &crl, store, &trusted_certificate);
    EXPECT_EQ(NX_SECURE_X509_CRL_SIGNATURE_CHECK_FAILED, status);

    test_public_cipher_method.nx_crypto_algorithm = 0;
    status = _nx_secure_x509_crl_verify(&revoked_certificate, &crl, store, &trusted_certificate);
    EXPECT_EQ(NX_SECURE_X509_UNSUPPORTED_PUBLIC_CIPHER, status);

    printf("SUCCESS!\n");
    test_control_return(0);
}
#else
#ifdef CTEST
void test_application_define(void *first_unused_memory);
void test_application_define(void *first_unused_memory)
#else
void nx_secure_x509_crl_verify_test_application_define(void *first_unused_memory)
#endif
{

    /* Print out test information banner.  */
    printf("NetX Secure Test:   TLS X509 CRL Verify Test.......................N/A\n");
    test_control_return(3);
}
#endif
